package com.bs.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bs.bean.Detail;
import com.bs.service.DetailService;
import com.bs.utils.Result;

@RestController
@RequestMapping(value="/json/detail",produces="application/json; charset=utf-8")
public class DetailController {
	@Autowired
	private DetailService detailService;

	@Autowired
	private HttpServletRequest request;
	@Autowired
	private HttpSession session;
	@RequestMapping("/findById")
	public Result findByID(Integer id) {
		try {
			Detail detail = detailService.findById(id);
			return Result.success().put("detail", detail);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return Result.fail(e.getLocalizedMessage());
		}
	}
	
	@RequestMapping("/insert")
	public Result insert(Detail detail) {
		try {
			detailService.insert(detail);
			System.out.println(detail);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return Result.fail(e.getMessage());
		}
		return Result.success();
	}


}
